package Layouts 
{
	import Entities.*;
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.text.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Game extends Sprite {
		
		[Embed(source="../Resources/Texts/kidfont.ttf", fontName = "Kidfont",
		fontStyle = "normal" ,fontWeight = "bold", embedAsCFF= "false")]
		private static var font:Class;
		private var text_format:TextFormat;
		private var text:TextField;
		private var title:TextField;
		
		[Embed(source="../Resources/Images/Levels/level_bg.jpg")]
		private var level_bg:Class;
		
		private var par:Main;
		
		private var W:uint;
		private var H:uint;
		
		private var bg:Sprite;
		private var owl_cont:Sprite;
		private	var condor_cont:Sprite;
		private	var text_cont:Sprite;
		private var q_a_cont:Sprite;
		private var level_cont:Sprite;
		private var timer:Timer;
		
		private var player:Player = new Player();
		private var owl:Owl;
		private var condor:Condor;
		private var hole1:Hole;
		private var hole2:Hole;
		private var hole3:Hole;
		
		private var fall_t:uint;
		private var line:uint;
		private var event1_detect:Sprite;
		private var event2_detect:Sprite;
		private var event3_detect:Sprite;
		
		private var dropout_zone:Sprite;
		private var dropout_detect:Sprite;
		private var dragged_sprite:Object;
		private var draggable:Boolean = false;
		private var dragging:Boolean = false;
		
		private var ev1_happened:Boolean = false;
		private var ev2_happened:Boolean = false;
		private var ev3_happened:Boolean = false;
		private var ev1_detec_passed:Boolean = false;
		private var ev2_detec_passed:Boolean = false;
		private var ev3_detec_passed:Boolean = false;
		
		private var end_level_win:Sprite;
		private var end_level_fail:Sprite;
		private var won_level:Boolean = false;
		private var failed_level:Boolean = false;
		
		private var question1:TextField;
		private var q1button1:Sprite;
		private var q1button1_label:TextField;
		private var q1button2:Sprite;
		private var q1button2_label:TextField;
		private var q1button3:Sprite;
		private var q1button3_label:TextField;
		private var q1button4:Sprite;
		private var q1button4_label:TextField;
		
		private var question2:TextField;
		private var q2button1:Sprite;
		private var q2button1_label:TextField;
		private var q2button2:Sprite;
		private var q2button2_label:TextField;
		private var q2button3:Sprite;
		private var q2button3_label:TextField;
		private var q2button4:Sprite;
		private var q2button4_label:TextField;
		
		private var question3:TextField;
		private var q3button1:Sprite;
		private var q3button1_label:TextField;
		private var q3button2:Sprite;
		private var q3button2_label:TextField;
		private var q3button3:Sprite;
		private var q3button3_label:TextField;
		private var q3button4:Sprite;
		private var q3button4_label:TextField;
		
		private var is_reading:Boolean;
		
		public function Game(parent:Main):void	{
			addEventListener(Event.ADDED_TO_STAGE, init);
			par = parent;			
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			W = stage.stageWidth;
			H = stage.stageHeight;
			
			par.screen_manager.select_text();
			
			bg = new Sprite();
			bg.graphics.beginFill(0xFCF089);
			bg.graphics.drawRect(0 , 0, W, H);
			bg.graphics.endFill();
			addChild(bg);
			
			text_format = new TextFormat();
			text_format.font = "Kidfont";
			text_format.size = 20;
			
			owl_cont = new Sprite();
			owl_cont.graphics.beginFill(0xC99837);
			owl_cont.graphics.drawRoundRect(0, 0, H * 9/32 , H * 3/8,W / 72);
			owl_cont.graphics.endFill();
			addChild(owl_cont);
			owl_cont.x = W / 36;
			owl_cont.y = W / 36;
			
			owl = new Owl();
			owl_cont.addChild(owl);
			owl.x = owl_cont.width/2 - owl.width/2;
			owl.y = owl_cont.height/2 - owl.height/2;
			
			timer = new Timer(this);
			addChild(timer);
			timer.x = W / 36;
			timer.y = W * 22 / 216 + owl_cont.height;
			
			level_cont = new Sprite();
			level_cont.graphics.beginFill(0xC99837);
			level_cont.graphics.drawRoundRect(0, 0, W * 34 / 36, H /3, W / 72);
			level_cont.graphics.endFill();
			addChild(level_cont);
			level_cont.x = W / 36;
			level_cont.y = H - (level_cont.height + W / 36);
			
			var level_bg_instance:Bitmap = new level_bg();
			level_cont.addChild(level_bg_instance);
			level_bg_instance.scaleX = 1.475;
			level_bg_instance.scaleY = 0.75;
			level_bg_instance.x = level_cont.width / 2 - level_bg_instance.width / 2;
			level_bg_instance.y = level_cont.height / 2 - level_bg_instance.height / 2;
			
			line = level_cont.height / 2;
			
			event1_detect = new Sprite();
			event1_detect.graphics.beginFill(0xE9CE83);
			event1_detect.graphics.drawRect(0, 0, 10, 50);
			event1_detect.graphics.endFill();
			level_cont.addChild(event1_detect);
			event1_detect.x = level_bg_instance.width * 2/7 - event1_detect.width/2 ;
			event1_detect.y = line;
			
			event2_detect = new Sprite();
			event2_detect.graphics.beginFill(0xE9CE83);
			event2_detect.graphics.drawRect(0, 0, 10, 50);
			event2_detect.graphics.endFill();
			level_cont.addChild(event2_detect);
			event2_detect.x = level_bg_instance.width * 4/7 - event2_detect.width/2 ;
			event2_detect.y = line;
			
			event3_detect = new Sprite();
			event3_detect.graphics.beginFill(0xE9CE83);
			event3_detect.graphics.drawRect(0, 0, 10, 50);
			event3_detect.graphics.endFill();
			level_cont.addChild(event3_detect);
			event3_detect.x = level_bg_instance.width * 6/7 - event3_detect.width/2 ;
			event3_detect.y = line;
			
			end_level_win = new Sprite();
			end_level_win.graphics.beginFill(0xE9CE83);
			end_level_win.graphics.drawRect(0, 0, 10, 50);
			end_level_win.graphics.endFill();
			level_cont.addChild(end_level_win);
			end_level_win.x = level_bg_instance.width - end_level_win.width/2 ;
			end_level_win.y = line;
			
			end_level_fail = new Sprite();
			end_level_fail.graphics.beginFill(0xE9CE83);
			end_level_fail.graphics.drawRect(0, 0, level_cont.width, level_cont.height / 72);
			end_level_fail.graphics.endFill();
			level_cont.addChild(end_level_fail);
			end_level_fail.x = 0;
			end_level_fail.y = level_cont.height * 71 / 72;
			
			hole1 = new Hole();
			level_cont.addChild(hole1);
			hole1.x = event1_detect.x + (level_cont.width / 2 - level_bg_instance.width / 2)- (hole1.width/2);
			hole1.y = line + hole1.height * 6;
			
			hole2 = new Hole();
			level_cont.addChild(hole2);
			hole2.x = event2_detect.x + (level_cont.width / 2 - level_bg_instance.width / 2)- (hole2.width/2);
			hole2.y = line + hole2.height * 6;
			
			hole3 = new Hole();
			level_cont.addChild(hole3);
			hole3.x = event3_detect.x + (level_cont.width / 2 - level_bg_instance.width / 2) - (hole3.width/2);
			hole3.y = line + hole3.height * 6;
			
			level_cont.addChild(player);
			player.x = level_cont.height / 36;
			player.y = line;
			
			read_answer_cycle(true);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			is_reading = true;
			fall_t = 0;
			
			event1_detect.visible = false;
			event2_detect.visible = false;
			event3_detect.visible = false;
			end_level_win.visible = false;
			end_level_fail.visible = false;
			
		}
		
		private function read_answer_cycle(read:Boolean):void {
			
			if (read) {
				
				if (condor_cont != null) { removeChild(condor_cont) };
				if (q_a_cont != null) { removeChild(q_a_cont) };
				
				text_cont = new Sprite();
				text_cont.graphics.beginFill(0xC99837);
				text_cont.graphics.drawRoundRect(0 , 0, W * 33 / 36 - H * 9/32, H * 7/16,W / 72);
				text_cont.graphics.endFill();
				addChild(text_cont);
				text_cont.x = W / 18 + owl_cont.width;
				text_cont.y = W / 36;
				
				title = new TextField();
				title.embedFonts= true;
				title.defaultTextFormat = text_format;
				title.selectable = false;
				title.autoSize = TextFieldAutoSize.LEFT;
				title.text = par.screen_manager.title;
				text_cont.addChild(title);
				title.x = W / 72;
				title.y = W / 72;
				title.wordWrap = true;
				
				text = new TextField();
				text.embedFonts= true;
				text.defaultTextFormat = text_format;
				text.selectable = false;
				text.text = par.screen_manager.text;
				text_cont.addChild(text);
				text.x = W / 72;
				text.y = W / 36 + title.height;
				text.width = text_cont.width - W / 36;
				text.height = text_cont.height - (W / 24 + title.height);
				text.wordWrap = true;
				
			}
			else {
				
				if (text_cont != null) { removeChild(text_cont) };
				
				condor_cont = new Sprite();
				condor_cont.graphics.beginFill(0xC99837);
				condor_cont.graphics.drawRoundRect(0, 0, H * 9/32, H * 7/16, W / 72);
				condor_cont.graphics.endFill();
				addChild(condor_cont);
				condor_cont.x = W * 35 / 36 - condor_cont.width;
				condor_cont.y = W / 36;
				
				condor = new Condor();
				condor_cont.addChild(condor);
				condor.x = condor_cont.width/2 - condor.width/2;
				condor.y = condor_cont.height/3 - condor.height/2;
				
				dropout_zone = new Sprite();
				dropout_zone.graphics.beginFill(0xE9CE83);
				dropout_zone.graphics.drawCircle(0, 0, condor_cont.width / 6);
				dropout_zone.graphics.endFill();
				condor_cont.addChild(dropout_zone);
				dropout_zone.x = condor_cont.width / 2 - dropout_zone.width/3;
				dropout_zone.y = condor_cont.height * 8 / 12 + dropout_zone.height / 2;
				
				question_setter(1);
				
			}
			
		}
		private	function question_setter(number:uint):void {
			
			switch(number) {
				case 1:
					
					q_a_cont = new Sprite();
					q_a_cont.graphics.beginFill(0xC99837,0.1);
					q_a_cont.graphics.drawRoundRect(0 , 0, W * 32 / 36 - H * 9/32, H * 7/16,W / 72);
					q_a_cont.graphics.endFill();
					addChild(q_a_cont);
					q_a_cont.x = W / 18 + owl_cont.width;
					q_a_cont.y = W / 36;
					
					question1 = new TextField();
					question1.embedFonts= true;
					question1.defaultTextFormat = text_format;
					question1.selectable = false;
					question1.text = par.screen_manager.question1;
					question1.width = q_a_cont.width - W / 36;
					question1.height = q_a_cont.height - W / 36;
					question1.wordWrap = true;
					q_a_cont.addChild(question1);
					question1.x = W / 72;
					question1.y = W / 72;
					
					q1button1 = new Sprite();
					q1button1.graphics.beginFill(0xC99837);
					q1button1.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q1button1.graphics.endFill();
					q_a_cont.addChild(q1button1);
					q1button1.x = q_a_cont.height / 72;
					q1button1.y = q_a_cont.height / 5 + (q_a_cont.height / 10 - q1button1.height / 2);
					q1button1.buttonMode = true;
					q1button1.useHandCursor = true;
					q1button1.addEventListener(MouseEvent.CLICK, drag_click);
					q1button2 = new Sprite();
					q1button2.graphics.beginFill(0xC99837);
					q1button2.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q1button2.graphics.endFill();
					q_a_cont.addChild(q1button2);
					q1button2.x = q_a_cont.height / 72;
					q1button2.y = q_a_cont.height * 2 / 5 + (q_a_cont.height / 10 - q1button1.height / 2);
					q1button2.buttonMode = true;
					q1button2.useHandCursor = true;
					q1button2.addEventListener(MouseEvent.CLICK, drag_click);
					q1button3 = new Sprite();
					q1button3.graphics.beginFill(0xC99837);
					q1button3.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q1button3.graphics.endFill();
					q_a_cont.addChild(q1button3);
					q1button3.x = q_a_cont.height / 72;
					q1button3.y = q_a_cont.height * 3 / 5 + (q_a_cont.height / 10 - q1button1.height / 2);
					q1button3.buttonMode = true;
					q1button3.useHandCursor = true;
					q1button3.addEventListener(MouseEvent.CLICK, drag_click);
					q1button4 = new Sprite();
					q1button4.graphics.beginFill(0xC99837);
					q1button4.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q1button4.graphics.endFill();
					q_a_cont.addChild(q1button4);
					q1button4.x = q_a_cont.height / 72;
					q1button4.y = q_a_cont.height * 4 / 5 + (q_a_cont.height / 10 - q1button1.height / 2);
					q1button4.buttonMode = true;
					q1button4.useHandCursor = true;
					q1button4.addEventListener(MouseEvent.CLICK, drag_click);
					
					q1button1_label = new TextField();
					q1button1_label.embedFonts= true;
					q1button1_label.defaultTextFormat = text_format;
					q1button1_label.selectable = false;
					q1button1_label.autoSize = TextFieldAutoSize.LEFT;
					q1button1_label.text = par.screen_manager.q1answer1;
					q1button1.addChild(q1button1_label);
					q1button1_label.x = q1button1.width/2 - q1button1_label.width/2;
					q1button1_label.y = q1button1.height / 2 - q1button1_label.height / 2;
					q1button2_label = new TextField();
					q1button2_label.embedFonts= true;
					q1button2_label.defaultTextFormat = text_format;
					q1button2_label.selectable = false;
					q1button2_label.autoSize = TextFieldAutoSize.LEFT;
					q1button2_label.text = par.screen_manager.q1answer2;
					q1button2.addChild(q1button2_label);
					q1button2_label.x = q1button2.width/2 - q1button2_label.width/2;
					q1button2_label.y = q1button2.height / 2 - q1button2_label.height / 2;
					q1button3_label = new TextField();
					q1button3_label.embedFonts= true;
					q1button3_label.defaultTextFormat = text_format;
					q1button3_label.selectable = false;
					q1button3_label.autoSize = TextFieldAutoSize.LEFT;
					q1button3_label.text = par.screen_manager.q1answer3;
					q1button3.addChild(q1button3_label);
					q1button3_label.x = q1button3.width/2 - q1button3_label.width/2;
					q1button3_label.y = q1button3.height / 2 - q1button3_label.height / 2;
					q1button4_label = new TextField();
					q1button4_label.embedFonts= true;
					q1button4_label.defaultTextFormat = text_format;
					q1button4_label.selectable = false;
					q1button4_label.autoSize = TextFieldAutoSize.LEFT;
					q1button4_label.text = par.screen_manager.q1answer4;
					q1button4.addChild(q1button4_label);
					q1button4_label.x = q1button4.width/2 - q1button4_label.width/2;
					q1button4_label.y = q1button4.height/2 - q1button4_label.height/2;
					
					draggable = true;
					
					dropout_detect = new Sprite();
					dropout_detect.graphics.beginFill(0xC34837,0);
					dropout_detect.graphics.drawCircle(0, 0, condor_cont.width / 6);
					dropout_detect.graphics.endFill();
					addChild(dropout_detect);
					dropout_detect.x = dropout_zone.x + condor_cont.x;
					dropout_detect.y = dropout_zone.y + condor_cont.y;
					dropout_detect.addEventListener(MouseEvent.MOUSE_OVER, on_dropout);
					
					break;
					
				case 2:
					
					
					q1button1.removeEventListener(MouseEvent.CLICK, drag_click);
					q1button2.removeEventListener(MouseEvent.CLICK, drag_click);
					q1button3.removeEventListener(MouseEvent.CLICK, drag_click);
					q1button4.removeEventListener(MouseEvent.CLICK, drag_click);
					dropout_detect.removeEventListener(MouseEvent.MOUSE_OVER, on_dropout);
					
					removeChild(q_a_cont);
					removeChild(dropout_detect);
					
					q_a_cont = new Sprite();
					q_a_cont.graphics.beginFill(0xC99837,0.1);
					q_a_cont.graphics.drawRoundRect(0 , 0, W * 32 / 36 - H * 9/32, H * 7/16,W / 72);
					q_a_cont.graphics.endFill();
					addChild(q_a_cont);
					q_a_cont.x = W / 18 + owl_cont.width;
					q_a_cont.y = W / 36;
					
					question2 = new TextField();
					question2.embedFonts= true;
					question2.defaultTextFormat = text_format;
					question2.selectable = false;
					question2.text = par.screen_manager.question2;
					question2.width = q_a_cont.width - W / 36;
					question2.height = q_a_cont.height - W / 36;
					question2.wordWrap = true;
					q_a_cont.addChild(question2);
					question2.x = W / 72;
					question2.y = W / 72;
					
					q2button1 = new Sprite();
					q2button1.graphics.beginFill(0xC99837);
					q2button1.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q2button1.graphics.endFill();
					q_a_cont.addChild(q2button1);
					q2button1.x = q_a_cont.height / 72;
					q2button1.y = q_a_cont.height / 5 + (q_a_cont.height / 10 - q2button1.height / 2);
					q2button1.buttonMode = true;
					q2button1.useHandCursor = true;
					q2button1.addEventListener(MouseEvent.CLICK, drag_click);
					q2button2 = new Sprite();
					q2button2.graphics.beginFill(0xC99837);
					q2button2.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q2button2.graphics.endFill();
					q_a_cont.addChild(q2button2);
					q2button2.x = q_a_cont.height / 72;
					q2button2.y = q_a_cont.height * 2 / 5 + (q_a_cont.height / 10 - q2button1.height / 2);
					q2button2.buttonMode = true;
					q2button2.useHandCursor = true;
					q2button2.addEventListener(MouseEvent.CLICK, drag_click);
					q2button3 = new Sprite();
					q2button3.graphics.beginFill(0xC99837);
					q2button3.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q2button3.graphics.endFill();
					q_a_cont.addChild(q2button3);
					q2button3.x = q_a_cont.height / 72;
					q2button3.y = q_a_cont.height * 3 / 5 + (q_a_cont.height / 10 - q2button1.height / 2);
					q2button3.buttonMode = true;
					q2button3.useHandCursor = true;
					q2button3.addEventListener(MouseEvent.CLICK, drag_click);
					q2button4 = new Sprite();
					q2button4.graphics.beginFill(0xC99837);
					q2button4.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q2button4.graphics.endFill();
					q_a_cont.addChild(q2button4);
					q2button4.x = q_a_cont.height / 72;
					q2button4.y = q_a_cont.height * 4 / 5 + (q_a_cont.height / 10 - q2button1.height / 2);
					q2button4.buttonMode = true;
					q2button4.useHandCursor = true;
					q2button4.addEventListener(MouseEvent.CLICK, drag_click);
					
					q2button1_label = new TextField();
					q2button1_label.embedFonts= true;
					q2button1_label.defaultTextFormat = text_format;
					q2button1_label.selectable = false;
					q2button1_label.autoSize = TextFieldAutoSize.LEFT;
					q2button1_label.text = par.screen_manager.q2answer1;
					q2button1.addChild(q2button1_label);
					q2button1_label.x = q2button1.width/2 - q2button1_label.width/2;
					q2button1_label.y = q2button1.height / 2 - q2button1_label.height / 2;
					q2button2_label = new TextField();
					q2button2_label.embedFonts= true;
					q2button2_label.defaultTextFormat = text_format;
					q2button2_label.selectable = false;
					q2button2_label.autoSize = TextFieldAutoSize.LEFT;
					q2button2_label.text = par.screen_manager.q2answer2;
					q2button2.addChild(q2button2_label);
					q2button2_label.x = q2button2.width/2 - q2button2_label.width/2;
					q2button2_label.y = q2button2.height / 2 - q2button2_label.height / 2;
					q2button3_label = new TextField();
					q2button3_label.embedFonts= true;
					q2button3_label.defaultTextFormat = text_format;
					q2button3_label.selectable = false;
					q2button3_label.autoSize = TextFieldAutoSize.LEFT;
					q2button3_label.text = par.screen_manager.q2answer3;
					q2button3.addChild(q2button3_label);
					q2button3_label.x = q2button3.width/2 - q2button3_label.width/2;
					q2button3_label.y = q2button3.height / 2 - q2button3_label.height / 2;
					q2button4_label = new TextField();
					q2button4_label.embedFonts= true;
					q2button4_label.defaultTextFormat = text_format;
					q2button4_label.selectable = false;
					q2button4_label.autoSize = TextFieldAutoSize.LEFT;
					q2button4_label.text = par.screen_manager.q2answer4;
					q2button4.addChild(q2button4_label);
					q2button4_label.x = q2button4.width/2 - q2button4_label.width/2;
					q2button4_label.y = q2button4.height/2 - q2button4_label.height/2;
					
					draggable = true;
					
					dropout_detect = new Sprite();
					dropout_detect.graphics.beginFill(0xC34837,0);
					dropout_detect.graphics.drawCircle(0, 0, condor_cont.width / 6);
					dropout_detect.graphics.endFill();
					addChild(dropout_detect);
					dropout_detect.x = dropout_zone.x + condor_cont.x;
					dropout_detect.y = dropout_zone.y + condor_cont.y;
					dropout_detect.addEventListener(MouseEvent.MOUSE_OVER, on_dropout);
					
					break;
					
				case 3:
					
					q2button1.removeEventListener(MouseEvent.CLICK, drag_click);
					q2button2.removeEventListener(MouseEvent.CLICK, drag_click);
					q2button3.removeEventListener(MouseEvent.CLICK, drag_click);
					q2button4.removeEventListener(MouseEvent.CLICK, drag_click);
					dropout_detect.removeEventListener(MouseEvent.MOUSE_OVER, on_dropout);
					
					removeChild(q_a_cont);
					removeChild(dropout_detect);
					
					q_a_cont = new Sprite();
					q_a_cont.graphics.beginFill(0xC99837,0.1);
					q_a_cont.graphics.drawRoundRect(0 , 0, W * 32 / 36 - H * 9/32, H * 7/16,W / 72);
					q_a_cont.graphics.endFill();
					addChild(q_a_cont);
					q_a_cont.x = W / 18 + owl_cont.width;
					q_a_cont.y = W / 36;
					
					question3 = new TextField();
					question3.embedFonts= true;
					question3.defaultTextFormat = text_format;
					question3.selectable = false;
					question3.text = par.screen_manager.question3;
					question3.width = q_a_cont.width - W / 36;
					question3.height = q_a_cont.height - W / 36;
					question3.wordWrap = true;
					q_a_cont.addChild(question3);
					question3.x = W / 72;
					question3.y = W / 72;
					
					q3button1 = new Sprite();
					q3button1.graphics.beginFill(0xC99837);
					q3button1.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q3button1.graphics.endFill();
					q_a_cont.addChild(q3button1);
					q3button1.x = q_a_cont.height / 72;
					q3button1.y = q_a_cont.height / 5 + (q_a_cont.height / 10 - q3button1.height / 2);
					q3button1.buttonMode = true;
					q3button1.useHandCursor = true;
					q3button1.addEventListener(MouseEvent.CLICK, drag_click);
					q3button2 = new Sprite();
					q3button2.graphics.beginFill(0xC99837);
					q3button2.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 ,W / 72);
					q3button2.graphics.endFill();
					q_a_cont.addChild(q3button2);
					q3button2.x = q_a_cont.height / 72;
					q3button2.y = q_a_cont.height * 2 / 5 + (q_a_cont.height / 10 - q3button1.height / 2);
					q3button2.buttonMode = true;
					q3button2.useHandCursor = true;
					q3button2.addEventListener(MouseEvent.CLICK, drag_click);
					q3button3 = new Sprite();
					q3button3.graphics.beginFill(0xC99837);
					q3button3.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q3button3.graphics.endFill();
					q_a_cont.addChild(q3button3);
					q3button3.x = q_a_cont.height / 72;
					q3button3.y = q_a_cont.height * 3 / 5 + (q_a_cont.height / 10 - q3button1.height / 2);
					q3button3.buttonMode = true;
					q3button3.useHandCursor = true;
					q3button3.addEventListener(MouseEvent.CLICK, drag_click);
					q3button4 = new Sprite();
					q3button4.graphics.beginFill(0xC99837);
					q3button4.graphics.drawRoundRect(0 , 0, q_a_cont.width * 17/36 , q_a_cont.height * 3/20 , W / 72);
					q3button4.graphics.endFill();
					q_a_cont.addChild(q3button4);
					q3button4.x = q_a_cont.height / 72;
					q3button4.y = q_a_cont.height * 4 / 5 + (q_a_cont.height / 10 - q2button1.height / 2);
					q3button4.buttonMode = true;
					q3button4.useHandCursor = true;
					q3button4.addEventListener(MouseEvent.CLICK, drag_click);
					
					q3button1_label = new TextField();
					q3button1_label.embedFonts= true;
					q3button1_label.defaultTextFormat = text_format;
					q3button1_label.selectable = false;
					q3button1_label.autoSize = TextFieldAutoSize.LEFT;
					q3button1_label.text = par.screen_manager.q3answer1;
					q3button1.addChild(q3button1_label);
					q3button1_label.x = q3button1.width/2 - q3button1_label.width/2;
					q3button1_label.y = q3button1.height / 2 - q3button1_label.height / 2;
					q3button2_label = new TextField();
					q3button2_label.embedFonts= true;
					q3button2_label.defaultTextFormat = text_format;
					q3button2_label.selectable = false;
					q3button2_label.autoSize = TextFieldAutoSize.LEFT;
					q3button2_label.text = par.screen_manager.q3answer2;
					q3button2.addChild(q3button2_label);
					q3button2_label.x = q3button2.width/2 - q3button2_label.width/2;
					q3button2_label.y = q3button2.height / 2 - q3button2_label.height / 2;
					q3button3_label = new TextField();
					q3button3_label.embedFonts= true;
					q3button3_label.defaultTextFormat = text_format;
					q3button3_label.selectable = false;
					q3button3_label.autoSize = TextFieldAutoSize.LEFT;
					q3button3_label.text = par.screen_manager.q3answer3;
					q3button3.addChild(q3button3_label);
					q3button3_label.x = q3button3.width/2 - q3button3_label.width/2;
					q3button3_label.y = q3button3.height / 2 - q3button3_label.height / 2;
					q3button4_label = new TextField();
					q3button4_label.embedFonts= true;
					q3button4_label.defaultTextFormat = text_format;
					q3button4_label.selectable = false;
					q3button4_label.autoSize = TextFieldAutoSize.LEFT;
					q3button4_label.text = par.screen_manager.q3answer4;
					q3button4.addChild(q3button4_label);
					q3button4_label.x = q3button4.width/2 - q3button4_label.width/2;
					q3button4_label.y = q3button4.height/2 - q3button4_label.height/2;
					
					draggable = true;
					
					dropout_detect = new Sprite();
					dropout_detect.graphics.beginFill(0xC34837,0);
					dropout_detect.graphics.drawCircle(0, 0, condor_cont.width / 6);
					dropout_detect.graphics.endFill();
					addChild(dropout_detect);
					dropout_detect.x = dropout_zone.x + condor_cont.x;
					dropout_detect.y = dropout_zone.y + condor_cont.y;
					dropout_detect.addEventListener(MouseEvent.MOUSE_OVER, on_dropout);
					
					break;
			}
		}
		
		private function onEnterFrame(e:Event):void {
			
			if (timer.timer.width <= 1 && is_reading) {
				timer.timer.scaleX = 1;
				read_answer_cycle(false);
				is_reading = false;
				player.is_moving = true;
			}
			
			if (is_reading) {
				if (timer.timer.width >= 1) { timer.timer.scaleX -= 0.003 };
			} else {
				if (timer.timer.width >= 1) { timer.timer.scaleX -= 0.003 };
				if (!ev1_happened) {
					if (player.is_moving) {
						player.x += 0.003 * ((event1_detect.x + event1_detect.width / 2) - (level_cont.height / 36 + player.width / 2))
						}
					if (get_distance(player, event1_detect) <= 0) { event_1() };
				} else if (get_distance(player, event1_detect) >= 0) {
					player.x += 0.01 * ((event1_detect.x + event1_detect.width / 2) - (level_cont.height / 36 + player.width / 2))
					} else if (!ev2_happened){
					if (player.is_moving) {
						player.x += 0.003 * ((event2_detect.x + event2_detect.width / 2) - (event1_detect.x + event1_detect.width / 2))
						}
					if (get_distance(player, event2_detect) <= 0) { event_2() };
				} else if (get_distance(player, event2_detect) >= 0) {
					player.x += 0.01 * ((event2_detect.x + event2_detect.width / 2) - (event1_detect.x + event1_detect.width/2))
					} else if (!ev3_happened){
					if (player.is_moving) {
						player.x += 0.003 * ((event3_detect.x + event3_detect.width / 2) - (event2_detect.x + event2_detect.width / 2))
						};
					if (get_distance(player, event3_detect) <= 0) { event_3() };
				} else if (get_distance(player, event3_detect) >= 0) {
					player.x += 0.01 * ((event3_detect.x + event3_detect.width / 2) - (event2_detect.x + event2_detect.width/2))
					} else if (get_distance(player, end_level_win) >= 0) {
					player.x += 0.01 * ((end_level_win.x + end_level_win.width / 2) - (event3_detect.x + event3_detect.width / 2))
					}
				
				if (player.is_falling) { fall_t++; player.y = line + 0.09 * Math.pow(fall_t, 2) };
				
			}
			
			if (ev1_happened && !ev1_detec_passed && Math.abs( get_distance(player, event1_detect)) <= 1.25) {
				timer.timer.scaleX = 1; ev1_detec_passed = true; question_setter(2) };
			if (ev2_happened && !ev2_detec_passed && Math.abs( get_distance(player, event2_detect)) <= 1.25) {
				timer.timer.scaleX = 1; ev2_detec_passed = true; question_setter(3) };
			if (ev3_happened && !ev3_detec_passed && Math.abs( get_distance(player, event3_detect)) <= 1.25) {
				timer.timer.scaleX = 1; ev3_detec_passed = true };
			
			if (player.hitTestObject(end_level_fail)) { failed_level = true; lose() };
			if (player.hitTestObject(end_level_win)) { won_level = true; win() };
			
		}
		
		private function get_distance(object1:Sprite,object2:Sprite):Number{
			var distance:Number;
			distance = (object2.x + object2.width / 2) - (object1.x + object1.width / 2);
			return distance;
		}
		
		private function drag_click(e:MouseEvent):void {
			if (draggable) {
				dragged_sprite = e.target;
				drag_sprite("Start");
			}			
		}
		
		private function drag_sprite(command:String):void {
			switch(command) {
				case "Start": dragged_sprite.startDrag(); dragging = true; break;
				case "Stop" : dragged_sprite.stopDrag(); dragging = false; dragged_sprite.visible = false;
					dragged_sprite.buttonMode = false; dragged_sprite.useHandCursor = false; break;
			}
		}
		
		private function event_1():void {
			player.is_moving = false;
			player.is_falling = true;
		}
		private function event_2():void {
			player.is_moving = false;
			player.is_falling = true;
		}		
		private function event_3():void {
			player.is_moving = false;
			player.is_falling = true;
		}
		
		private function on_dropout(e:MouseEvent):void {
			if (dragging) {
				if (!ev1_happened) { drag_sprite("Stop"), answer_detect() }
				else if (!ev2_happened) { drag_sprite("Stop"), answer_detect() }
				else if (!ev3_happened) { drag_sprite("Stop"), answer_detect() }
			}
		}
		
		private function answer_detect():void {
			if (question1) {
				switch (par.screen_manager.right_answer1) {
					case 1: if (dragged_sprite == q1button1) { ev1_happened = true, draggable = false } ; break;
					case 2: if (dragged_sprite == q1button2) { ev1_happened = true, draggable = false } ; break;
					case 3: if (dragged_sprite == q1button3) { ev1_happened = true, draggable = false } ; break;
					case 4: if (dragged_sprite == q1button4) { ev1_happened = true, draggable = false } ; break;
				}
			}
			if (question2) {
				switch (par.screen_manager.right_answer2) {
					case 1: if (dragged_sprite == q2button1) { ev2_happened = true, draggable = false } ; break;
					case 2: if (dragged_sprite == q2button2) { ev2_happened = true, draggable = false } ; break;
					case 3: if (dragged_sprite == q2button3) { ev2_happened = true, draggable = false } ; break;
					case 4: if (dragged_sprite == q2button4) { ev2_happened = true, draggable = false } ; break;
				}
			}
			if (question3) {
				switch (par.screen_manager.right_answer3) {
					case 1: if (dragged_sprite == q3button1) { ev3_happened = true, draggable = false } ; break;
					case 2: if (dragged_sprite == q3button2) { ev3_happened = true, draggable = false } ; break;
					case 3: if (dragged_sprite == q3button3) { ev3_happened = true, draggable = false } ; break;
					case 4: if (dragged_sprite == q3button4) { ev3_happened = true, draggable = false } ; break;
				}
			}
		}
		
		private function lose():void {
			if (failed_level) { par.screen_manager.goToScreen("RetryMenu"); failed_level=false }
		}
		private function win():void {
			if (won_level){
				if (par.screen_manager.game_files.data.save_level <= 2) {
					par.screen_manager.goToScreen("NextLevelMenu")
				} else { par.screen_manager.goToScreen("WinMenu") };
				won_level = false;
				
				removeEventListener(Event.ENTER_FRAME, onEnterFrame);
				q3button1.removeEventListener(MouseEvent.CLICK, drag_click);
				q3button2.removeEventListener(MouseEvent.CLICK, drag_click);
				q3button3.removeEventListener(MouseEvent.CLICK, drag_click);
				q3button4.removeEventListener(MouseEvent.CLICK, drag_click);
				dropout_detect.removeEventListener(MouseEvent.MOUSE_OVER, on_dropout);
				
			}
		}
		
	}

}